Skip to content

Added support for passing driver options to MongoClient (SSL support) #460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2015

Conversation

nsmithuk
Copy link
Contributor

@nsmithuk nsmithuk commented Apr 6, 2015

With MongoDB v3.0 now supporting SSL out of the box, it would be really useful to be able to configure the MongoClient's driver options, where certificate details are set.

An example Laravel configuration file would then look like:

'mongodb' => array(
    'driver'   => 'mongodb',
    'host'     => 'mongodb.local',
    'port'     => 27017,
    'username' => 'username',
    'password' => 'password',
    'database' => 'database',
    'options'  => array(
        "ssl" => true,
    ),
    'driver_options' => array(
        'context' => stream_context_create(array(
            "ssl" => array(
                "local_cert"        => 'client.pem',
                "cafile"            => 'ca.crt',
                "allow_self_signed" => false,
                "verify_peer"       => true,
                "verify_peer_name"  => true,
                "verify_expiry"     => true,
            ),
        ))
    )
),

Used mainly for configuring SSL details.
@nsmithuk nsmithuk changed the title Added support for passing driver options to MongoClient Added support for passing driver options to MongoClient (SSL support) Apr 6, 2015
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.15%) to 96.41% when pulling 759cbdc on NSmithUK:AddMongoClientDriverOptions into 8304a46 on jenssegers:master.

@nsmithuk
Copy link
Contributor Author

nsmithuk commented Apr 6, 2015

If you choose to merge this, please can you also apply it to the 4.2 branch.

jenssegers added a commit that referenced this pull request May 3, 2015
Added support for passing driver options to MongoClient (SSL support)
@jenssegers jenssegers merged commit faba869 into mongodb:master May 3, 2015
@enginkartal
Copy link

enginkartal commented Aug 2, 2016

thank you :)

`<?php

return [
'default' => 'mongodb',

'connections' => [
    'mongodb' => [
        'driver'   => 'mongodb',
        'host'     => env('MONGODB_HOST'),
        'port'     => env('MONGODB_PORT'),
        'username' => env('MONGODB_USERNAME'),
        'password' => env('MONGODB_PASSWORD'),
        'database' => env('MONGODB_DATABASE'),
        'options'  => ['replicaSet' => env('MONGODB_REPLICASET'),'database'=>'admin','ssl'=>true],
        'driver_options' => [
            'context' => stream_context_create([
                "ssl" => [
                    "verify_peer"       => false,
                    "verify_peer_name"  => false,
                    "verify_expiry"     => false
                ]])],
    ]
]

];`

@shqear-mawdoo3
Copy link

@enginkartal it gives an error:

MongoDB/Driver/Exception/InvalidArgumentException with message '"context" driver option is not a valid Stream-Context resource'

here is my configurations

'mongodb' => [
            'driver'   => 'mongodb',
            'host'     => env('MONGO_DB_HOST', 'localhost'),
            'port'     => env('MONGO_DB_PORT', 27017),
            'database' => env('MONGO_DB_DATABASE'),
            'username' => env('MONGO_DB_USERNAME'),
            'password' => env('MONGO_DB_PASSWORD'),
            'options'  => [
                "ssl"      => true,
                'database' => env('MONGO_DB_DATABASE')
            ],
            'driver_options' => [
                'context' => [
                    "ssl" => [
                        "local_cert"        => base_path('rds-combined-ca-bundle.pem'),
                        "allow_self_signed" => true,
                        "verify_peer"       => false,
                        "verify_peer_name"  => false,
                        "verify_expiry"     => false
                    ]
                ]
            ]
        ],

@ghost
Copy link

ghost commented May 7, 2021

@enginkartal it gives an error:

MongoDB/Driver/Exception/InvalidArgumentException with message '"context" driver option is not a valid Stream-Context resource'

here is my configurations

'mongodb' => [
            'driver'   => 'mongodb',
            'host'     => env('MONGO_DB_HOST', 'localhost'),
            'port'     => env('MONGO_DB_PORT', 27017),
            'database' => env('MONGO_DB_DATABASE'),
            'username' => env('MONGO_DB_USERNAME'),
            'password' => env('MONGO_DB_PASSWORD'),
            'options'  => [
                "ssl"      => true,
                'database' => env('MONGO_DB_DATABASE')
            ],
            'driver_options' => [
                'context' => [
                    "ssl" => [
                        "local_cert"        => base_path('rds-combined-ca-bundle.pem'),
                        "allow_self_signed" => true,
                        "verify_peer"       => false,
                        "verify_peer_name"  => false,
                        "verify_expiry"     => false
                    ]
                ]
            ]
        ],

I also have this problem, I tried to put it this way, and the error

@mongodb mongodb locked and limited conversation to collaborators May 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants